<?php
namespace backend\controllers;

use Yii;
use yii\web\Controller;
use common\collection\Common;
use common\collection\BackendCommon;
use common\helpers\PublicFun;
use backend\config\routeParams;

/**
 * JurisdictionController
 */
class JurisdictionController extends Controller
{
    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
        ];
    }


    public  function beforeAction($action){
        if(BackendCommon::init()){
            if(BackendCommon::rbac()){
                return true;
            }else{
                Yii::$app->response->redirect( ['site/error']);
            }
        }else{
            Yii::$app->response->redirect( ['login/index']);
        }
    }
    //用户管理
    public function actionUser()
    {
        return $this->render('user');
    }

    //等级管理
    public function actionLevel()
    {
        return $this->render('level');
    }

    //菜单管理
    public function actionMenu()
    {
        return $this->render('menu');
    }
    //用户等级绑定
    public function actionBinding()
    {
        return $this->render('binding');
    }

    //获取管理员列表
    public function actionGetAdminList()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $JsonData['Fields'] = '*';
        $url = routeParams::HttpUrl('MytipGetList');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        $ret = [
            'limit' => $JsonData['PageSize'],
            'page' => $JsonData["PageNo"],
            'total' => $result["TotalCounts"],
            'data' => $result['Models']
        ];
        die(json_encode($ret));
    }

    //重置密码
    public function actionAdminResetPwd()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $url = routeParams::HttpUrl('MytipResetPwd');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }


    //获取管理员列表
    public function actionGetLevelList()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $JsonData = [
            'PageSize' =>100,
            'PageNo' =>1
        ];
        $JsonData['MytipId'] = Common::GetMytipId();
        $url = routeParams::HttpUrl('MytipLevelGetList');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        $ret = [
            'total' => $result["TotalCounts"],
            'data' => $result['Models']
        ];
        die(json_encode($ret));
    }
    //编辑等级信息
    public function actionMytipLevelUpdate()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $JsonData['MytipId'] =  Common::GetMytipId();
        $url = routeParams::HttpUrl('PCEnterpriseEmployeeLevelSave');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }
    //编辑等级信息
    public function actionLevelActionGetList()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $JsonData['MytipId'] =  Common::GetMytipId();
        $url = routeParams::HttpUrl('LevelControllerActionGetList');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }

    //保存集客多多等级关联控制器
    public function actionLevelActionSave()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $JsonData['MytipId'] =  Common::GetMytipId();
        $url = routeParams::HttpUrl('LevelControllerActionSave');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }
    //获取控制器列表
    public function actionControllerInfoGetList()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $url = routeParams::HttpUrl('ControllerInfoGetList');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        $ret = [
            'limit' => $JsonData['PageSize'],
            'page' => $JsonData["PageNo"],
            'total' => $result["TotalCounts"],
            'data' => $result['Models']
        ];
        die(json_encode($ret));
    }
    //新建控制器
    public function actionControllerInfoCreate()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        if(isset($JsonData['ControllerId'])){
            $url = routeParams::HttpUrl('ControllerInfoUpdate');
        }else{
            $url = routeParams::HttpUrl('ControllerInfoCreate');
        }
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }

    //获取action列表
    public function actionActInfoGetList()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $JsonData['MytipId'] = Common::GetMytipId();
        $url = routeParams::HttpUrl('ActionInfoGetList');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        $ret = [
            'total' => $result["TotalCount"],
            'data' => $result['Models']
        ];
        die(json_encode($ret));
    }

    //新建控制器
    public function actionActionInfoCreate()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        if(isset($JsonData['ActionId'])){
            $url = routeParams::HttpUrl('ActionInfoGetUpdate');
        }else{
            $url = routeParams::HttpUrl('ActionInfoGetCreate');
        }
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }

    //保存控制器与模块关联
    public function actionActionMapSave()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        if(!isset($JsonData['ActionList'])){
            $JsonData['ActionList'] = array();
        }
        $url = routeParams::HttpUrl('ControllerActionMapSave');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }


    //新建控制器
    public function actionMytipSetstate()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $url = routeParams::HttpUrl('MytipSetState');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }
    //编辑用户信息
    public function actionAlertMytipInfo()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $JsonData['MytipId'] = Common::GetMytipId();
        $url = routeParams::HttpUrl('AlertMytipInfo');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }

    //创建用户信息
    public function actionMytipInfoCreate()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $url = routeParams::HttpUrl('MytipInfoCreate');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }

    //删除用户信息
    public function actionMytipDelete()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $url = routeParams::HttpUrl('MytipDelete');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }


    //删除用户信息
    public function actionMytipUpdate()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $url = routeParams::HttpUrl('MytipUpdate');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }

    //删除员工等级
    public function actionEmployeeLevelDel()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $url = routeParams::HttpUrl('PCEnterpriseEmployeeLevelDel');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }







}
